package yy;

public class StrStr {
    public static void main(String[] args){
        String s1 = "leetcode";
        String s2 = "eet";
        int result = strStr(s1,s2);
        System.out.println(result);
    }
    public static int strStr(String haystack, String needle) {
        char[] s1 = haystack.toCharArray();
        char[] s2 = needle.toCharArray();

        int n = haystack.length();
        int m = needle.length();

        int p;
        int i,j;
        for(i = 0; i<n - m  + 1; i++){
            p=i;
            for (j = 0; j < needle.length(); j++){
                if(s2[j] == s1[p]){
                    p++;
                }else {
                    break;
                }
            }
            if(j==needle.length()){
                return i;
            }
        }
        return -1;

    }
}

//abaaba
